home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
msh20.zip
/
MSHFILES.ZIP
/
DEMO2.MSH
< prev
next >
Wrap
Text File
|
1992-03-26
|
4KB
|
110 lines
| file DEMO2.MSH
hide_all
("Welcome to Mi-Shell"
"
Copyright(C) PMC/OPENetwork 1990
"
message)message1!
message1
("Demo2" swap message)m!
" This is an advanced tutorial where we'll explore the
language and the debugger. The Mi-Shell script language
is a stack language, like Postcript and FORTH. If
you are not familiar with either, this tutorial should
help as an introduction." m
" When the debugger window comes up, you will see 2 parts:
the top line reflects the source code submitted, together
with a caret pointing to the token being interpreted.
below the dotted line, you will see the contents of the stack.
" m
" First, we will push 2 on the stack, push another 2 on the stack,
then push a + on the stack. The + will add 2+2 and return a 4.
The whole code will be
2 2 + 3 + drop
To step thru in the debugger, push s (for step) repeatedly and
watch the stack. " m
|
(true debug!2 2 + 3 + drop false debug!)#
" You may have noticed that after the computation, we issued
a drop, which dropped the result from the stack.
Then we had the code
false debug !
This is how we turn off the debug mode: we push false on the
stack, then push the system variable debug, then push !,
the assignment function. This causes the value false to be
assigned to debug. In most languages, this would be written
as debug = false
We did that, so that invoking this message would
be immediate, rather than a slow step thru process. " m
" Let us make an even simpler assignment,
similar to the usual XYZ = 23
This is done with the statement 23 XYZ !
There is not much to see in the debugger, but we'll
follow it anyway." m
(true debug!23 "XYZ" ! false debug!)#
" Now let's watch the concatenation of two strings,
which is done with the & operator." m
(true debug!"hello, " "world" & drop false debug!)#
" A boolean variable is one whose values are true or false.
In the Mi-Shell script, every value is a string, and a value
of \"false\" or \"\" (an empty string) are understood as false.
Every other string is considered true." m
" Let us examine the ifelse statement.
First we look at the syntax:
Boolean (action1) (action2) ifelse
will run action2 if Boolean is false (or the empty string),
and action1 otherwise.
Now, we will look at an example:
XYZ (message1) (quit) ifelse!
will execute message1
because XYZ is not false (we set to 23 a few windows ago). " m
(true debug!"XYZ" (message1) (quit) ifelse! false debug!)#
" A more interesting example is the definition of
debug_toggle, a standard definition you can find
in STDDEFS.MSH.
(debug(false debug!)(true debug!)ifelse)debug_toggle!
This may look formidable, but is actually rather simple.
The whole thing is a piece of code (the outer parentheses),
defining debug_toggle.
Inside, we see 4 items:
debug the system variable which is either true or false,
(false debug!) action1, which turns debug off,
(true debug!) action2, which turns debug on,
ifelse which causes action1 or action2 to occur,
based on the value of debug.
If you can follow this example, you have gone a long
way towards understanding stack languages in general,
and Mi-Shell in particular." m
" Let us now look at a while loop.
((stack_size 0 > ) (drop) while)clean_stack!
This is a definition for clean_stack which can
be found in STDDEFS.MSH. In english, it says
while the stack size (a primitive) is positive,
drop the top from the stack. It is clear that the
syntax is:
(boolean) (action) while
and means while boolean is true, perform action.
Let us see it work. the code will be
3 2 clean_stack" m
(true debug!3 2 clean_stack false debug!)#
" Now that you are almost done with this advanced tutorial,
let us take a look at the Mi-Shell script that it
is written in. We'll use pager, Mi-Shell's built-in
viewer. The Up, Down, PgUp and PgDwn keys will be
active, and you can use F1 for help and ESC to quit. " m
prog_dir "DEMO2.MSH"& pager
" Well, so long now. . . You have graduated!
The next logical steps are to study the primitives
in the Reference Manual, to study the standard
definitions in stddefs.msh and menu.msh, and
to start writing your own!" m
hide_all
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||